package com.lagou.servlet;

import com.lagou.dao.UserService;
import com.lagou.dao.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class UserServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String username = req.getParameter("username");
        String passsword = req.getParameter("passsword");
        UserService service = new UserServiceImpl();
        boolean userExists = service.isUserExists(username, passsword);

        if (userExists ) {
            req.setAttribute("operType","list");

            HttpSession session = req.getSession();
            // 2.获取共享数据
            session.setAttribute("isLogin",true);
            System.out.println("UserServlet----isLogin---->"+true);

            req.getRequestDispatcher("/studentServlet").forward(req,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
